//
//  HYSalonDetaController.m
//  KaiJing
//
//  Created by lanou on 16/1/15.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "HYSalonDetaController.h"
#import "HYSalonTableHeaderView.h"
#import "PKRequestManager.h"
#import "HYDateSalonModel.h"
#import <UIImageView+WebCache.h>
#import "CJSalonHotController.h"
#import "HYSalonNewController.h"
#import "HYMoreShortModel.h"

@interface HYSalonDetaController ()<UIScrollViewDelegate>
@property (nonatomic, strong) HYSalonTableHeaderView *headerView;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) NSMutableArray *hotArray;
@property (nonatomic, strong) HYDateSalonModel *dateModel;
@property (nonatomic, strong) CJSalonHotController *hotVc;
@property (nonatomic, strong) HYSalonNewController *salonNewVc;
@property (nonatomic, strong) UIScrollView *scrollView ;
@property (nonatomic, strong) NSMutableArray *movieNewArray;

@end
static NSString *identifier = @"HYSalonDetaController";


@implementation HYSalonDetaController

- (void)viewDidLoad {
    [super viewDidLoad];
    //self.view.backgroundColor = [UIColor greenColor];
    _dataArray = [NSMutableArray array];
    _hotArray = [NSMutableArray array];
    _movieNewArray = [NSMutableArray array];
    [self setUpData];
    
}


-(void) setUpData {
    NSString *string = [NSString stringWithFormat:@"http://morguo.com/forum.php?mod=collection&action=view&ctid=%@&androidflag=1&appfrom=ios&iosversion=3.13&page=1",_model.ctid];
    [PKRequestManager requestWithUrlString:string parDic:nil method:GET finish:^(NSDictionary *dataDic) {
        NSDictionary *dic = dataDic[@"data"];
        _dateModel = [[HYDateSalonModel alloc] init];
        [_dateModel setValuesForKeysWithDictionary:dic];
        [_dataArray addObject:_dateModel];
        
        
        NSArray *listNewArray = dataDic[@"data"][@"list"];
        for (NSDictionary *dic in listNewArray) {
            HYMoreShortModel *model = [[HYMoreShortModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [_movieNewArray addObject:model];
        }
        
        
        
        [self addScrollView];
    } error:^(NSError *error) {
        SZLog(@"%@",error);
    }];
}

- (void)addChildViewController {
    NSString *string = [NSString stringWithFormat:@"http://morguo.com/forum.php?mod=collection&action=view&ctid=%@&orderby=hot&androidflag=1&appfrom=ios&iosversion=3.13&page=1",_model.ctid];
    [PKRequestManager requestWithUrlString:string parDic:nil method:GET finish:^(NSDictionary *dataDic) {
        NSArray *listArray = dataDic[@"data"][@"list"];
        for (NSDictionary *dic in listArray) {
            HYMoreShortModel *model = [[HYMoreShortModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [_hotArray addObject:model];
        }
        
        _hotVc = [[CJSalonHotController alloc] init];
        _hotVc.tableView.frame = CGRectMake(0, kScreenHeight / 2 - 20, kScreenWidth, kScreenHeight);
        _hotVc.array = _hotArray;
        [self addChildViewController:_hotVc];
        _hotVc.tableView.rowHeight = 180;
        [_scrollView addSubview:_hotVc.tableView];
        _hotVc.tableView.backgroundColor = [UIColor redColor];
        
  
        
    } error:^(NSError *error) {
        SZLog(@"%@",error);
    }];

    
    
    _salonNewVc = [[HYSalonNewController alloc] init];
    _salonNewVc.array = _movieNewArray;
    _salonNewVc.tableView.frame = CGRectMake(0, kScreenHeight / 2 - 20, kScreenWidth, kScreenHeight);
    [self addChildViewController:_salonNewVc];
    _salonNewVc.tableView.rowHeight = 180;
    _salonNewVc.tableView.alwaysBounceVertical = NO;
    [_scrollView addSubview:_salonNewVc.view];
    _salonNewVc.tableView.backgroundColor = [UIColor yellowColor];
    
    
}


- (void)addScrollView {
    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 113)];
    _scrollView.contentSize = CGSizeMake(kScreenWidth , (kScreenHeight - 113) *2);
    
    _scrollView.contentOffset = CGPointMake(kScreenWidth, 0);
    //设置缩放比例!!!
    _scrollView.minimumZoomScale = 0.5;
    _scrollView.maximumZoomScale = 2;
    
    //设置回弹效果
    _scrollView.bounces = YES;
    //scrollView.alwaysBounceHorizontal = YES;
    _scrollView.alwaysBounceVertical = YES;
    //设置代理
    _scrollView.delegate = self;
    
    //是否整屏翻动
    
    _scrollView.backgroundColor = kRandomClolor;
    [self.view addSubview:_scrollView];
    
#pragma mark --初始化表头view
    _headerView = [[HYSalonTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight / 2)];
   
   // _headerView.backgroundColor = kRandomClolor;
    [_scrollView addSubview:_headerView];
    
#pragma mark--给表头控件赋值
    _headerView.name.text = _dateModel.name;
    NSString *threadnum = [NSString stringWithFormat:@"%@人参与",_dateModel.threadnum];
    _headerView.threadnum.text = threadnum;
    
    _headerView.timeLabel.text = _dateModel.createtime;
    _headerView.desc.text = _dateModel.desc;
    _headerView.founderusername.text = _dateModel.founderusername;
    NSString *icon = [NSString stringWithFormat:@"http://morguo.com/%@",_dateModel.icon];
    [_headerView.headerImageView sd_setImageWithURL:[NSURL URLWithString:icon]];
    
    [_headerView.leftButton addTarget:self action:@selector(leftButton:) forControlEvents:(UIControlEventTouchUpInside)];
    
    [_headerView.rightButton addTarget:self action:@selector(rightButton:) forControlEvents:(UIControlEventTouchUpInside)];
    [self addChildViewController];
    
}

- (void)leftButton:(UIButton *)button {
    [UIView transitionFromView:_hotVc.view toView:_salonNewVc.view duration:0.5 options:(UIViewAnimationOptionTransitionCrossDissolve) completion:nil];
}

- (void)rightButton:(UIButton *) button {
    [UIView transitionFromView:_salonNewVc.view toView:_hotVc.view duration:0.5 options:(UIViewAnimationOptionTransitionCrossDissolve) completion:nil];
}












@end
